// 红包算法
// 路径问题
// 小数相加（精度问题）
// a == 1 && a == 2 && a == 3 等式成立
// const [a, b] = {a: 1, b:2} 等式可执行

// async-validate

function redPackage(total, num, min) {
    let remind = total;
    let res = [];
    for (let i = 0; i < num; i++) {
        if (i === num - 1) {
            res.push(remind.toFixed(2))
        } else {
            let max = remind - min * (num - (i + 1))
            let randomNum = (Math.random() * (max - min) + min).toFixed(2)
            remind = remind - randomNum
            res.push(randomNum);
        }
    }
    return res;
}
console.log(redPackage(1, 3, 0.1))



function floatAdd(num1, num2) {
    let arr1 = num1.toString().split('.');
    let arr2 = num2.toString().split('.');

    let max = Math.max(arr1[1].length, arr2[1].length);

    let n1 = num1 * Math.pow(10, max);
    let n2 = num2 * Math.pow(10, max);
    return (n1 + n2) / Math.pow(10, max)
}
console.log(floatAdd(1.1, 1.23))




let a = {
    n: 1,
    valueOf: function () {
        return this.n++
    }
}
console.log(a == 1 && a == 2 && a == 3)


// 使等式成立 对象结构变数组
Object.prototype[Symbol.iterator] = function () {
    return Object.values(this)[Symbol.iterator]()
}
var [aa, bb] = { aa: 1, bb: 2 }
console.log(aa, bb)




function findAllPaths(arr, start, end) {
    let graph = {};
    for (let i = 0; i < arr.length; i++) {
        let [start, end] = arr[i].split('-');
        if (graph[start]) {
            graph[start].push(end)
        } else {
            graph[start] = [end]
        }
    }
    console.log(graph)

    let temp = [start];
    let res = [];
    let set = new Set()
    let dfs = (temp, target, dep) => {
        if(dep === target){
            res.push(temp)
        }

        set.add(dep)
        for(let item of graph[dep] || []){
            if(!set.has(item)){
                dfs(temp.concat(item), target, item)
            }
        }
        set.delete(dep)
    }
    dfs(temp, end, start)

    return res;

}
const arr = ['a-b', 'b-c', 'a-d', 'c-d', 'd-f'];
const start = 'a';
const end = 'f';
const allPaths = findAllPaths(arr, start, end);
console.log(allPaths);
